package midimaker.ui;

import java.awt.GridLayout;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class ControllerPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private final JButton start;
	private final JButton stop;
	private final JButton tempoUp;
	private final JButton tempoDown;
	private final JButton sendit;
	
	public ControllerPanel () {
		start = new JButton("Start");
		stop = new JButton("Stop");
		tempoUp = new JButton("Tempo Up");
		tempoDown = new JButton("Tempo Down");
		sendit = new JButton("Sendit");
		
		this.add(start);
		this.add(stop);
		this.add(tempoUp);
		this.add(tempoDown);
		this.add(sendit);
		
		this.setLayout(new GridLayout(5,1));
	}
	
	public void setStartListener(MouseListener ml) {
		MouseListener[] mouseListeners = this.start.getMouseListeners(); 
		if (mouseListeners.length > 1) {
			this.start.removeMouseListener(mouseListeners[1]);
		}
		this.start.addMouseListener(ml);
	}
	
	public void setStopListener(MouseListener ml) {
		MouseListener[] mouseListeners = this.stop.getMouseListeners(); 
		if (mouseListeners.length > 1) {
			this.stop.removeMouseListener(mouseListeners[1]);
		}
		this.stop.addMouseListener(ml);
	}
	
	public void setTempoUpListener(MouseListener ml) {
		MouseListener[] mouseListeners = this.tempoUp.getMouseListeners(); 
		if (mouseListeners.length > 1) {
			this.tempoUp.removeMouseListener(mouseListeners[1]);
		}
		this.tempoUp.addMouseListener(ml);
	}
	
	public void setTempoDownListener(MouseListener ml) {
		MouseListener[] mouseListeners = this.tempoDown.getMouseListeners(); 
		if (mouseListeners.length > 1) {
			this.tempoDown.removeMouseListener(mouseListeners[1]);
		}
		this.tempoDown.addMouseListener(ml);
	}
	
}
